<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">


      <el-form-item label="设备名称" prop="epName">
        <el-input
          v-model="queryParams.epName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备位置" prop="epLocation">
        <el-input
          v-model="queryParams.epLocation"
          placeholder="请输入设备位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['assets:TbEquipmentParameter:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['assets:TbEquipmentParameter:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['assets:TbEquipmentParameter:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['assets:TbEquipmentParameter:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="TbEquipmentParameterList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="epId" />
      <el-table-column label="设备编码


" align="center" prop="epEid" />
      <el-table-column label="原厂编号" align="center" prop="epOid" />
      <el-table-column label="设备名称" align="center" prop="epName" />
      <el-table-column label="设备位置" align="center" prop="epLocation" />
      <el-table-column label="设备类型" align="center" prop="epType" />
      <el-table-column label="详细位置" align="center" prop="epDetailed" />
      <el-table-column label="型号" align="center" prop="epModel" />
      <el-table-column label="设备品牌" align="center" prop="epBrand" />
      <el-table-column label="购买时间" align="center" prop="epBuytime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.epBuytime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="使用时间" align="center" prop="epUsetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.epUsetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="维护时间" align="center" prop="epMaintenancetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.epMaintenancetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="维护周期" align="center" prop="epMaintenance" />
      <el-table-column label="部门，人员" align="center" prop="uId" />
      <el-table-column label="状态0：正常1：已报废" align="center" prop="epState" />
      <el-table-column label="二维码" align="center" prop="epQrCode" />
      <el-table-column label="设备是否存在" align="center" prop="epYn" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['assets:TbEquipmentParameter:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['assets:TbEquipmentParameter:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改设备台账对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备编码


" prop="epEid">
          <el-input v-model="form.epEid" placeholder="请输入设备编码


" />
        </el-form-item>
        <el-form-item label="原厂编号" prop="epOid">
          <el-input v-model="form.epOid" placeholder="请输入原厂编号" />
        </el-form-item>
        <el-form-item label="设备名称" prop="epName">
          <el-input v-model="form.epName" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="设备位置" prop="epLocation">
          <el-input v-model="form.epLocation" placeholder="请输入设备位置" />
        </el-form-item>
        <el-form-item label="详细位置" prop="epDetailed">
          <el-input v-model="form.epDetailed" placeholder="请输入详细位置" />
        </el-form-item>
        <el-form-item label="型号" prop="epModel">
          <el-input v-model="form.epModel" placeholder="请输入型号" />
        </el-form-item>
        <el-form-item label="设备品牌" prop="epBrand">
          <el-input v-model="form.epBrand" placeholder="请输入设备品牌" />
        </el-form-item>
        <el-form-item label="购买时间" prop="epBuytime">
          <el-date-picker clearable
            v-model="form.epBuytime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择购买时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="使用时间" prop="epUsetime">
          <el-date-picker clearable
            v-model="form.epUsetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择使用时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="维护时间" prop="epMaintenancetime">
          <el-date-picker clearable
            v-model="form.epMaintenancetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择维护时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="维护周期" prop="epMaintenance">
          <el-input v-model="form.epMaintenance" placeholder="请输入维护周期" />
        </el-form-item>
        <el-form-item label="部门，人员" prop="uId">
          <el-input v-model="form.uId" placeholder="请输入部门，人员" />
        </el-form-item>
        <el-form-item label="状态0：正常1：已报废" prop="epState">
          <el-input v-model="form.epState" placeholder="请输入状态0：正常1：已报废" />
        </el-form-item>
        <el-form-item label="二维码" prop="epQrCode">
          <el-input v-model="form.epQrCode" placeholder="请输入二维码" />
        </el-form-item>
        <el-form-item label="设备是否存在" prop="epYn">
          <el-input v-model="form.epYn" placeholder="请输入设备是否存在" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTbEquipmentParameter, getTbEquipmentParameter, delTbEquipmentParameter, addTbEquipmentParameter, updateTbEquipmentParameter } from "@/api/assets/TbEquipmentParameter";

export default {
  name: "TbEquipmentParameter",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备台账表格数据
      TbEquipmentParameterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        epName: null,
        epLocation: null,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备台账列表 */
    getList() {
      this.loading = true;
      listTbEquipmentParameter(this.queryParams).then(response => {
        this.TbEquipmentParameterList = response.data;
        this.total = response.data.length;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        epId: null,
        epEid: null,
        epOid: null,
        epName: null,
        epLocation: null,
        epType: null,
        epDetailed: null,
        epModel: null,
        epBrand: null,
        epBuytime: null,
        epUsetime: null,
        epMaintenancetime: null,
        epMaintenance: null,
        uId: null,
        epState: null,
        epQrCode: null,
        epYn: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.epId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备台账";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const epId = row.epId || this.ids
      getTbEquipmentParameter(epId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备台账";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.epId != null) {
            updateTbEquipmentParameter(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTbEquipmentParameter(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const epIds = row.epId || this.ids;
      this.$modal.confirm('是否确认删除设备台账编号为"' + epIds + '"的数据项？').then(function() {
        return delTbEquipmentParameter(epIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('assets/TbEquipmentParameter/export', {
        ...this.queryParams
      }, `TbEquipmentParameter_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
